#include "include/Variant.h"
#include <stdexcept>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <filesystem>
#include "include/ILogger.h"

#ifdef _WIN32
#include <winsock2.h>
#include <dbghelp.h>
#pragma comment(lib, "dbghelp.lib")  // Link against dbghelp library
#else
#include <arpa/inet.h>
#include <cxxabi.h>
#endif

namespace Tool
{

const std::string VariantJsonType = "VariantType";

/**
 * @description: 将C++类型名称进行反混淆（demangle）
 * @return {std::string} 返回反混淆后的类型名称
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 * @param {const char*} mangledName 混淆后的类型名称
 */
std::string DemangleTypeName(const char* mangledName)
{
#ifdef _WIN32
    char buffer[2048];
    DWORD size = sizeof(buffer);
    UnDecorateSymbolName(mangledName, buffer, size, UNDNAME_COMPLETE);
    std::string typeName(buffer);
    return CleanupTypeName(typeName);
#else
    // For GCC/Clang, use abi::__cxa_demangle
    int status = -1;
    std::unique_ptr<char, void(*)(void*)> result(
        abi::__cxa_demangle(mangledName, nullptr, nullptr, &status),
        std::free
    );
    return (status == 0) ? result.get() : mangledName;
#endif
}

std::string CleanupTypeName(std::string& typeName)
{
    typeName.erase(std::remove_if(typeName.begin(), typeName.end(), [](unsigned char ch) {
        return std::isspace(ch);}), typeName.end());

    std::string str = "class";
    size_t pos = typeName.find(str);
    while (pos != std::string::npos)
    {
        typeName.erase(pos, str.length());
        pos = typeName.find(str, pos);
    }

    pos = 0;
    str = "struct";
    pos = typeName.find(str);
    while (pos != std::string::npos)
    {
        typeName.erase(pos, str.length());
        pos = typeName.find(str, pos);
    }
    return typeName;
}

#ifdef _WIN32
ExportAPI std::unordered_map<std::string, Variant::SerializeStruct> Variant::m_typeRegistry;
ExportAPI std::unordered_map<std::string, std::pair<Variant::SerializeJsonFunc, Variant::DeserializeJsonFunc>> Variant::m_jsonTypeRegistry;
ExportAPI std::mutex Variant::m_typeRegistryMutex;
#else
std::unordered_map<std::string, Variant::SerializeStruct> Variant::m_typeRegistry;
std::unordered_map<std::string, std::pair<Variant::SerializeJsonFunc, Variant::DeserializeJsonFunc>> Variant::m_jsonTypeRegistry;
std::mutex Variant::m_typeRegistryMutex;
#endif

/**
 * @description: Variant的默认构造函数
 * @return {Variant} 返回一个默认构造的Variant对象
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
Variant::Variant()
    : m_private(std::make_unique<VariantPrivate>())
{
}

/**
 * @description: Variant的析构函数
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
Variant::~Variant() = default;

/**
 * @description: 使用bool值构造Variant对象
 * @return {Variant} 返回构造的Variant对象
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 * @param {bool} data 用于构造Variant的bool值
 */
Variant::Variant(bool data)
    : m_private(std::make_unique<VariantPrivate>(VariantType::Bool, data))
{
}

/**
 * @description: 使用int值构造Variant对象
 * @return {Variant} 返回构造的Variant对象
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 * @param {int} data 用于构造Variant的int值
 */
Variant::Variant(int data)
    : m_private(std::make_unique<VariantPrivate>(VariantType::Int, data))
{
}

/**
 * @description: 使用unsigned int值构造Variant对象
 * @return {Variant} 返回构造的Variant对象
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 * @param {unsigned int} data 用于构造Variant的unsigned int值
 */
Variant::Variant(unsigned int data)
    : m_private(std::make_unique<VariantPrivate>(VariantType::UInt, data))
{
}

/**
 * @description: 使用long long值构造Variant对象
 * @return {Variant} 返回构造的Variant对象
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 * @param {long long} data 用于构造Variant的long long值
 */
Variant::Variant(long long data)
    : m_private(std::make_unique<VariantPrivate>(VariantType::Long, data))
{
}

/**
 * @description: 使用unsigned long long值构造Variant对象
 * @return {Variant} 返回构造的Variant对象
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 * @param {unsigned long long} data 用于构造Variant的unsigned long long值
 */
Variant::Variant(unsigned long long data)
    : m_private(std::make_unique<VariantPrivate>(VariantType::ULong, data))
{
}

/**
 * @description: 使用float值构造Variant对象
 * @return {Variant} 返回构造的Variant对象
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 * @param {float} data 用于构造Variant的float值
 */
Variant::Variant(float data)
    : m_private(std::make_unique<VariantPrivate>(VariantType::Float, data))
{
}

/**
 * @description: 使用double值构造Variant对象
 * @return {Variant} 返回构造的Variant对象
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 * @param {double} data 用于构造Variant的double值
 */
Variant::Variant(double data)
    : m_private(std::make_unique<VariantPrivate>(VariantType::Double, data))
{
}

/**
 * @description: 使用std::string值构造Variant对象
 * @return {Variant} 返回构造的Variant对象
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 * @param {const std::string&} data 用于构造Variant的std::string值
 */
Variant::Variant(std::string&& data)
    : m_private(std::make_unique<VariantPrivate>(VariantType::String, std::any(std::in_place_type<std::string>, std::move(data))))
{
}

/**
 * @description: 使用std::string值构造Variant对象
 * 当你传递一个临时对象给 std::make_unique 时，它实际上会进行两次内存分配：一次为控制块（包含引用计数等），另一次为实际的对象
 * m_private(std::make_unique<VariantPrivate>(VariantPrivate(VariantType::String, data)))
 * m_private(std::make_unique<VariantPrivate>(VariantType::String, data))
 * @return {Variant} 返回构造的Variant对象
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 * @param {const std::string&} data 用于构造Variant的std::string值
 */
Variant::Variant(const std::string& data)
    : m_private(std::make_unique<VariantPrivate>(VariantType::String, std::any(std::in_place_type<std::string>, data)))
{
}

/**
 * @description: 使用C风格字符串构造Variant对象
 * @return {Variant} 返回构造的Variant对象
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 * @param {const char*} data 用于构造Variant的C风格字符串
 */
Variant::Variant(const char* data)
    : m_private(std::make_unique<VariantPrivate>(VariantType::String, std::any(std::in_place_type<std::string>, std::string(data))))
{
}

/**
 * @description: 使用std::vector<Variant>构造Variant对象
 * @return {Variant} 返回构造的Variant对象
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 * @param {const std::vector<Variant>&} data 用于构造Variant的std::vector<Variant>值
 */
Variant::Variant(const std::vector<Variant> &data)
    : m_private(std::make_unique<VariantPrivate>(VariantType::Vector, std::any(std::in_place_type<std::vector<Variant>>, data)))
{
}

/**
 * @description: 使用std::vector<Variant>&&构造Variant对象
 * @return {Variant} 返回构造的Variant对象
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 * @param {std::vector<Variant>&&} data 用于构造Variant的std::vector<Variant>值
 */
Variant::Variant(std::vector<Variant> &&data)
    : m_private(std::make_unique<VariantPrivate>(VariantType::Vector, std::any(std::in_place_type<std::vector<Variant>>, std::move(data))))
{
}

/**
 * @description: 使用std::list<Variant>构造Variant对象
 * @return {Variant} 返回构造的Variant对象
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 * @param {const std::list<Variant>&} data 用于构造Variant的std::list<Variant>值
 */
Variant::Variant(const std::list<Variant> &data)
    : m_private(std::make_unique<VariantPrivate>(VariantType::List, std::any(std::in_place_type<std::list<Variant>>, data)))
{
}

/**
 * @description: 使用std::list<Variant>&&构造Variant对象
 * @return {Variant} 返回构造的Variant对象
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 * @param {std::list<Variant>&&} data 用于构造Variant的std::list<Variant>值
 */
Variant::Variant(std::list<Variant> &&data)
    : m_private(std::make_unique<VariantPrivate>(VariantType::List, std::any(std::in_place_type<std::list<Variant>>, std::move(data))))
{
}

/**
 * @description: 使用std::set<Variant>构造Variant对象
 * @return {Variant} 返回构造的Variant对象
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 * @param {const std::set<Variant>&} data 用于构造Variant的std::set<Variant>值
 */
Variant::Variant(const std::set<Variant> &data)
    : m_private(std::make_unique<VariantPrivate>(VariantType::Set, std::any(std::in_place_type<std::set<Variant>>, data)))
{
}

/**
 * @description: 使用std::set<Variant>&&构造Variant对象
 * @return {Variant} 返回构造的Variant对象
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 * @param {const std::set<Variant>&} data 用于构造Variant的std::set<Variant>值
 */
Variant::Variant(std::set<Variant> &&data)
    : m_private(std::make_unique<VariantPrivate>(VariantType::Set, std::any(std::in_place_type<std::set<Variant>>, std::move(data))))
{
}


/**
 * @description: 使用std::map<std::string, Variant>构造Variant对象
 * @return {Variant} 返回构造的Variant对象
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 * @param {const std::map<std::string, Variant>&} data 用于构造Variant的std::map<std::string, Variant>值
 */
Variant::Variant(const std::map<std::string, Variant> &data)
    : m_private(std::make_unique<VariantPrivate>(VariantType::Map, std::any(std::in_place_type<std::map<std::string, Variant>>, data)))
{
}

/**
 * @description: 使用std::map<std::string, Variant>&&构造Variant对象
 * @return {Variant} 返回构造的Variant对象
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 * @param {const std::map<std::string, Variant>&} data 用于构造Variant的std::map<std::string, Variant>值
 */
Variant::Variant(std::map<std::string, Variant> &&data)
    : m_private(std::make_unique<VariantPrivate>(VariantType::Map, std::any(std::in_place_type<std::map<std::string, Variant>>, std::move(data))))
{
}

/**
 * @description: 使用std::unordered_map<std::string, Variant>构造Variant对象
 * @return {Variant} 返回构造的Variant对象
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 * @param {const std::unordered_map<std::string, Variant>&} data 用于构造Variant的std::unordered_map<std::string, Variant>值
 */
Variant::Variant(const std::unordered_map<std::string, Variant> &data)
    : m_private(std::make_unique<VariantPrivate>(VariantType::Hash, std::any(std::in_place_type<std::unordered_map<std::string, Variant>>, data)))
{
}

Variant::Variant(const std::initializer_list<Variant> &list)
{
    m_private = std::make_unique<VariantPrivate>(VariantType::Vector, std::any(std::in_place_type<VariantVector>, VariantVector()));
    VariantVector &vector = RefValue<VariantVector>();
    for (const auto& item : list)
    {
        vector.emplace_back(std::move(item));
    }
}

/**
 * @description: 使用std::unordered_map<std::string, Variant>&&构造Variant对象
 * @return {Variant} 返回构造的Variant对象
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 * @param {const std::unordered_map<std::string, Variant>&} data 用于构造Variant的std::unordered_map<std::string, Variant>值
 */
Variant::Variant(std::unordered_map<std::string, Variant> &&data)
    : m_private(std::make_unique<VariantPrivate>(VariantType::Hash, std::any(std::in_place_type<std::unordered_map<std::string, Variant>>, std::move(data))))
{
}

/**
 * @description: 使用std::vector<uint8_t>值构造Variant对象
 * @return {Variant} 返回构造的Variant对象
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 * @param {const std::vector<uint8_t>&} data 用于构造Variant的二进制数据
 */
Variant::Variant(const std::vector<uint8_t>& data)
    : m_private(std::make_unique<VariantPrivate>(VariantType::Binary, std::any(std::in_place_type<std::vector<uint8_t>>, data)))
{
}

/**
 * @description: 使用std::vector<uint8_t>右值构造Variant对象
 * @return {Variant} 返回构造的Variant对象
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 * @param {std::vector<uint8_t>&&} data 用于构造Variant的二进制数据
 */
Variant::Variant(std::vector<uint8_t>&& data)
    : m_private(std::make_unique<VariantPrivate>(VariantType::Binary, std::any(std::in_place_type<std::vector<uint8_t>>, std::move(data))))
{
}

/**
 * @description: Variant的拷贝构造函数
 * @return {Variant} 返回拷贝构造的Variant对象
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 * @param {const Variant&} data 用于拷贝构造的Variant对象
 */
Variant::Variant(const Variant &data)
    : m_private(std::make_unique<VariantPrivate>(*data.m_private))
    // : m_private(data.m_private)    // 如果赋值自身会导致循环引用问题
{
}

/**
 * @description: Variant的移动构造函数
 * @return {Variant} 返回移动构造的Variant对象
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 * @param {Variant&&} data 用于移动构造的Variant对象
 */
Variant::Variant(Variant &&data) noexcept
    : m_private(std::move(data.m_private))
{
}

/**
 * Variant::Variant(Variant &&data) noexcept: m_private(std::move(data.m_private)){}
 * Variant& Variant::operator=(Variant &&data) noexcept{if (this != &data){m_private = std::move(data.m_private);// data.m_private = nullptr;}return *this;}
 * 既能不抛异常地移动构造（is_nothrow_move_constructible），又能不抛异常地移动赋值（is_nothrow_move_assignable）时，这个赋值运算符才是 noexcept（不抛异常）的。
 * @return {Variant&} 返回当前对象的引用 移动拷贝赋值
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 * @param {const Variant&} data 用于拷贝赋值的Variant对象
 */
Variant& Variant::operator=(Variant other) noexcept(
    std::is_nothrow_move_constructible<VariantPrivate>::value &&    //不抛异常地移动构造（is_nothrow_move_constructible）
    std::is_nothrow_move_assignable<VariantPrivate>::value          //不抛异常地移动赋值（is_nothrow_move_assignable）
) 
{
    std::swap(m_private, other.m_private);
    return *this;
}

Variant::Variant(const std::vector<VariantHash>& value)
{
    VariantVector vec;
    vec.reserve(value.size());
    for (auto& map : value)
    {
        vec.emplace_back(map);
    }
    m_private = std::make_unique<VariantPrivate>(VariantType::Vector, std::any(std::in_place_type<VariantVector>, vec));
}

Variant::Variant(const std::vector<VariantHash>&& value)
{
    VariantVector vec;
    vec.reserve(value.size());
    for (auto& map : value)
    {
        vec.emplace_back(map);
    }
    m_private = std::make_unique<VariantPrivate>(VariantType::Vector, std::any(std::in_place_type<VariantVector>, std::move(vec)));
}

/**
 * @description: 获取Variant的类型
 * @return {VariantType} 返回Variant的类型
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
VariantType Variant::Type() const
{
    return m_private->m_type;
}

/**
 * @description: 将Variant转换为bool值
 * @return {bool} 返回Variant的bool值
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
bool Variant::ToBool() const
{
    return Value<bool>();
}

/**
 * @description: 将Variant转换为int值
 * @return {int} 返回Variant的int值
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
int Variant::ToInt() const
{
    return Value<int>();
}

/**
 * @description: 将Variant转换为unsigned int值
 * @return {unsigned int} 返回Variant的unsigned int值
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
unsigned int Variant::ToUInt() const
{
    return Value<unsigned int>();
}

/**
 * @description: 将Variant转换为long long值
 * @return {long long} 返回Variant的long long值
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
long long Variant::ToLong() const
{
    return Value<long long>();
}

/**
 * @description: 将Variant转换为unsigned long long值
 * @return {unsigned long long} 返回Variant的unsigned long long值
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
unsigned long long Variant::ToULong() const
{
    return Value<unsigned long long>();
}

/**
 * @description: 将Variant转换为float值
 * @return {float} 返回Variant的float值
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
float Variant::ToFloat() const
{
    return Value<float>();
}

/**
 * @description: 将Variant转换为double值
 * @return {double} 返回Variant的double值
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
double Variant::ToDouble() const
{
    return Value<double>();
}

/**
 * @description: 将Variant转换为std::string值
 * @return {std::string} 返回Variant的std::string值
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
std::string Variant::ToString() const
{
    return Value<std::string>();
}

/**
 * @description: 将Variant转换为std::vector<Variant>值
 * @return {VariantVector} 返回Variant的std::vector<Variant>值
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
VariantVector Variant::ToVector() const
{
    return Value<VariantVector>();
}

/**
 * @description: 将Variant转换为std::list<Variant>值
 * @return {VariantList} 返回Variant的std::list<Variant>值
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
VariantList Variant::ToList() const
{
    return Value<VariantList>();
}

/**
 * @description: 将Variant转换为std::set<Variant>值
 * @return {VariantSet} 返回Variant的std::set<Variant>值
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
VariantSet Variant::ToSet() const
{
    return Value<VariantSet>();
}

/**
 * @description: 将Variant转换为std::map<std::string, Variant>值
 * @return {VariantMap} 返回Variant的std::map<std::string, Variant>值
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
VariantMap Variant::ToMap() const
{
    return Value<VariantMap>();
}

/**
 * @description: 将Variant转换为std::unordered_map<std::string, Variant>值
 * @return {VariantHash} 返回Variant的std::unordered_map<std::string, Variant>值
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
VariantHash Variant::ToHash() const
{
    return Value<VariantHash>();
}

/**
 * @description: 将Variant转换为std::vector<uint8_t>
 * @return {std::vector<uint8_t>} 返回转换后的二进制数据
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
std::vector<uint8_t> Variant::ToBinary() const
{
    if (m_private->m_type == VariantType::Binary)
    {
        return std::any_cast<const std::vector<uint8_t>&>(m_private->m_data);
    }
    else if (m_private->m_type == VariantType::String)
    {
        // 如果是字符串类型，将其转换为二进制数据
        const std::string& str = std::any_cast<const std::string&>(m_private->m_data);
        return std::vector<uint8_t>(str.begin(), str.end());
    }
    else
    {
        LOG_ERROR("无法将当前类型转换为二进制数据");
    }
}

/**
 * @description: 将Variant转换为std::string值
 * @return {std::string} 返回Variant的std::string值
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
std::string &Variant::ToString()
{
    return RefValue<std::string>();
}

/**
 * @description: 将Variant转换为std::vector<Variant>值
 * @return {VariantVector} 返回Variant的std::vector<Variant>值
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
VariantVector &Variant::ToVector()
{
    return RefValue<VariantVector>();
}

/**
 * @description: 将Variant转换为std::list<Variant>值
 * @return {VariantList} 返回Variant的std::list<Variant>值
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
VariantList &Variant::ToList()
{
    return RefValue<VariantList>();
}

/**
 * @description: 将Variant转换为std::set<Variant>值
 * @return {VariantSet} 返回Variant的std::set<Variant>值
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
VariantSet &Variant::ToSet()
{
    return RefValue<VariantSet>();
}

/**
 * @description: 将Variant转换为std::map<std::string, Variant>值
 * @return {VariantMap} 返回Variant的std::map<std::string, Variant>值
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
VariantMap &Variant::ToMap()
{
    return RefValue<VariantMap>();
}

/**
 * @description: 将Variant转换为std::unordered_map<std::string, Variant>值
 * @return {VariantHash} 返回Variant的std::unordered_map<std::string, Variant>值
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
VariantHash &Variant::ToHash()
{
    return RefValue<VariantHash>();
}

/**
 * @description: 将Variant转换为std::vector<uint8_t>
 * @return {std::vector<uint8_t>} 返回转换后的二进制数据
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
std::vector<uint8_t> &Variant::ToBinary()
{
    return RefValue<std::vector<uint8_t>>();
}

/**
 * @description: 将Variant转换为bool类型
 * @return {bool} 返回Variant的bool值
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
Variant::operator bool() const
{
    return ToBool();
}

/**
 * @description: 将Variant转换为int类型
 * @return {int} 返回Variant的int值
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
Variant::operator int() const
{
    return ToInt();
}

Variant::operator long int() const
{
    return ToInt();
}

/**
 * @description: 将Variant转换为unsigned int类型
 * @return {unsigned int} 返回Variant的unsigned int值
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
Variant::operator unsigned int() const
{
    return ToUInt();
}

/**
 * @description: 将Variant转换为long long类型
 * @return {long long} 返回Variant的long long值
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
Variant::operator long long() const
{
    return ToLong();
}

/**
 * @description: 将Variant转换为unsigned long long类型
 * @return {unsigned long long} 返回Variant的unsigned long long值
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
Variant::operator unsigned long long() const
{
    return ToULong();
}

/**
 * @description: 将Variant转换为float类型
 * @return {float} 返回Variant的float值
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
Variant::operator float() const
{
    return ToFloat();
}

/**
 * @description: 将Variant转换为double类型
 * @return {double} 返回Variant的double值
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
Variant::operator double() const
{
    return ToDouble();
}

/**
 * @description: 将Variant转换为std::string类型
 * @return {std::string} 返回Variant的std::string值
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
Variant::operator std::string() const
{
    return ToString();
}

/**
 * @description: 将Variant转换为std::vector<Variant>类型
 * @return {std::vector<Variant>} 返回Variant的std::vector<Variant>值
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
Variant::operator std::vector<Variant>() const
{
    return ToVector();
}

/**
 * @description: 将Variant转换为std::list<Variant>类型
 * @return {std::list<Variant>} 返回Variant的std::list<Variant>值
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
Variant::operator std::list<Variant>() const
{
    return ToList();
}

/**
 * @description: 将Variant转换为std::set<Variant>类型
 * @return {std::set<Variant>} 返回Variant的std::set<Variant>值
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
Variant::operator std::set<Variant>() const
{
    return ToSet();
}

/**
 * @description: 将Variant转换为std::map<std::string, Variant>类型
 * @return {std::map<std::string, Variant>} 返回Variant的std::map<std::string, Variant>值
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
Variant::operator std::map<std::string, Variant>() const
{
    return ToMap();
}

/**
 * @description: 将Variant转换为std::unordered_map<std::string, Variant>类型
 * @return {std::unordered_map<std::string, Variant>} 返回Variant的std::unordered_map<std::string, Variant>值
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
Variant::operator std::unordered_map<std::string, Variant>() const
{
    return ToHash();
}

/**
 * @description: 将Variant转换为std::string&类型
 * @return {std::string&} 返回Variant的std::string&值
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
Variant::operator std::string &()
{
    return RefValue<std::string>();
}

/**
 * @description: 将Variant转换为std::vector<Variant>&类型
 * @return {std::vector<Variant>&} 返回Variant的std::vector<Variant>&值
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
Variant::operator std::vector<Variant> &()
{
    return RefValue<VariantVector>();
}

/**
 * @description: 将Variant转换为std::list<Variant>&类型
 * @return {std::list<Variant>&} 返回Variant的std::list<Variant>&值
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
Variant::operator std::list<Variant> &()
{
    return RefValue<VariantList>();
}

/**
 * @description: 将Variant转换为std::set<Variant>&类型
 * @return {std::set<Variant>&} 返回Variant的std::set<Variant>&值
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
Variant::operator std::set<Variant> &()
{
    return RefValue<VariantSet>();
}

/**
 * @description: 将Variant转换为std::map<std::string, Variant>&类型
 * @return {std::map<std::string, Variant>&} 返回Variant的std::map<std::string, Variant>&值
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
Variant::operator std::map<std::string, Variant> &()
{
    return RefValue<VariantMap>();
}

/**
 * @description: 将Variant转换为std::unordered_map<std::string, Variant>&类型
 * @return {std::unordered_map<std::string, Variant>&} 返回Variant的std::unordered_map<std::string, Variant>&值
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
Variant::operator std::unordered_map<std::string, Variant> &()
{
    return RefValue<VariantHash>();
}

const Variant &Variant::operator[](int index) const
{
    if (Type() != VariantType::Vector)
    {
        LOG_ERROR("使用下标访问，但是不是Vector");
    }
    const VariantVector &vector = RefValue<VariantVector>();
    if (vector.size() < index)
    {
        LOG_ERROR("超出下标");
    }
   return vector[index];
}

Variant Variant::Get(const std::string &key, const Variant &defaultValue) const
{
   if (Type() == VariantType::Hash)
   {
        auto& hash = RefValue<VariantHash>();
        auto it = hash.find(key);
        return it != hash.end() ? it->second : defaultValue;
   }
   if (Type() == VariantType::Map)
   {
        auto& map = RefValue<VariantMap>();
        auto it = map.find(key);
        return it != map.end() ? it->second : defaultValue;
   }
   return defaultValue;
}

const Variant &Variant::operator [](const std::string &key) const
{
    if (Type() == VariantType::Hash) 
    {
        const auto& hash = RefValue<VariantHash>();
        auto it = hash.find(key);
        if (it != hash.end()) 
        {
            return it->second;
        }
        LOG_ERROR("Key not found");
    }
    if (Type() == VariantType::Map) 
    {
        const auto& map = RefValue<VariantMap>();
        auto it = map.find(key);
        if (it != map.end()) 
        {
            return it->second;
        }
        LOG_ERROR("Key not found");
    }
    LOG_ERROR("使用键值访问，但是不是Hash或者map类型");
}

const Variant &Variant::operator [](const char *key) const
{
    if (Type() == VariantType::Hash) 
    {
        const auto& hash = RefValue<VariantHash>();
        auto it = hash.find(std::string(key));
        if (it != hash.end()) 
        {
            return it->second;
        }
        LOG_ERROR("Key not found");
    }
    if (Type() == VariantType::Map) 
    {
        const auto& map = RefValue<VariantMap>();
        auto it = map.find(std::string(key));
        if (it != map.end()) 
        {
            return it->second;
        }
        LOG_ERROR("Key not found");
    }
    LOG_ERROR("使用键值访问，但是不是Hash或者map类型");
}

/**
 * @description: 通过下标访问Variant中的元素（适用于Vector类型）
 * @return {Variant&} 返回Variant中指定下标的元素
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 * @param {int} index 要访问的下标
 */
Variant &Variant::operator [](int index)
{
    try
    {
        if(Type() == VariantType::None)
        {
            m_private = std::make_unique<VariantPrivate>(VariantType::Vector, std::any(VariantVector()));
            VariantVector& vector = RefValue<VariantVector>();
            for(int i = 0;i <= index; ++i)
            {
                vector.emplace_back(Variant());
            }
            return vector[index];
        }
        if(Type() == VariantType::Vector)
        {
            VariantVector& vector = RefValue<VariantVector>();;
            if(vector.size() > index)
            {
                return RefValue<VariantVector>()[index];
            }
            size_t count = vector.size();
            for(size_t i = 0; i <= index - count; ++i)
            {
                vector.emplace_back(Variant());
            }
            return vector[index];
        }
        else
        {
            LOG_ERROR("使用下标访问，但是不是Vector");
        }
    }
    catch (const std::bad_any_cast&)
    {
        LOG_ERROR("使用下标访问，但是不是Vector");
    }
}

/**
 * @description: 通过键值访问Variant中的元素（适用于Map或Hash类型）
 * @return {Variant&} 返回Variant中指定键值的元素
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 * @param {const std::string&} key 要访问的键值
 */
Variant &Variant::operator [](const std::string &key)
{
    try
    {
        if(m_private->m_type == VariantType::None)
        {
            m_private = std::make_unique<VariantPrivate>(VariantType::Hash, std::any(VariantHash()));
            return RefValue<VariantHash>()[key];
        }
        else if(m_private->m_type == VariantType::Hash)
        {
            return (RefValue<VariantHash>())[key];
        }
        if(m_private->m_type == VariantType::Map)
        {
            return (RefValue<VariantMap>())[key];
        }
        else
        {
            LOG_ERROR("使用键值访问，但是不是Map或者Hash");
        }
    }
    catch (const std::bad_any_cast&)
    {
        LOG_ERROR("使用键值访问，但是不是Map或者Hash");
    }
}

/**
 * @description: 通过键值访问Variant中的元素（适用于Map或Hash类型）
 * @return {Variant&} 返回Variant中指定键值的元素
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 * @param {const char*} key 要访问的键值
 */
Variant &Variant::operator [](const char *key)
{
    try
    {
        if(m_private->m_type == VariantType::None)
        {
            m_private = std::make_unique<VariantPrivate>(VariantType::Hash, std::any(VariantHash()));
            return RefValue<VariantHash>()[key];
        }
        else if(m_private->m_type == VariantType::Hash)
        {
            return RefValue<VariantHash>()[key];
        }
        if(m_private->m_type == VariantType::Map)
        {
            return RefValue<VariantMap>()[key];
        }
        else
        {
            LOG_ERROR("使用键值访问，但是不是Map或者Hash");
            throw std::runtime_error("使用键值访问，但是不是Map或者Hash.");
        }
    }
    catch (const std::bad_any_cast&)
    {
        LOG_ERROR("使用键值访问，但是不是Map或者Hash");
    }
}

/**
 * @description: 将Variant序列化到文件中
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 * @param {const std::string&} filename 文件名
 * @param {bool} binary 是否以二进制格式序列化
 */
bool Variant::SerializeToFile(const std::string &filename, VariantSerializeType type, bool jsonFormat)
{
    try
    {
        std::filesystem::path path(filename);
        if (!path.parent_path().empty() && !std::filesystem::exists(path.parent_path()))
        {
            if (!std::filesystem::create_directories(path.parent_path()))
            {
                LOG_ERROR("序列化失败，创建目录失败: %s", path.parent_path().string().c_str());
                return false;
            }
            LOG_INFO("成功创建目录: %s", path.parent_path().string().c_str());
        }

        std::ofstream file(filename, std::ios::binary | std::ios::trunc);
        if (!file.is_open())
        {
            LOG_ERROR("序列化失败，打开文件失败: %s", filename.c_str());
            return false;
        }
        if (type == VariantSerializeType::Binary)
        {
            //  SerializeBinary(file);
            const std::vector<uint8_t>& data = ToBinaryString();
            file.write(reinterpret_cast<const char*>(data.data()), data.size());
        }
        else
        {
            std::ofstream file(filename);
            if (!file.is_open())
            {
                LOG_ERROR("序列化失败，打开文件失败: %s", filename.c_str());
                return false;
            }
            // SerializeJson(file);
            const std::string& data = ToJsonString(jsonFormat);
            file.write(reinterpret_cast<const char*>(data.data()), data.size());
        }
        file.close();
        return true;
    }
    catch (const std::filesystem::filesystem_error& e)
    {
        LOG_ERROR("文件系统错误: %s（文件: %s）", e.what(), filename.c_str());
        return false;
    }
    catch (const std::exception& e)
    {
        LOG_ERROR("序列化失败，异常: %s（文件: %s）", e.what(), filename.c_str());
        return false;
    }
}

/**
 * @description: 从文件中反序列化Variant
 * @return {Variant} 返回反序列化后的Variant对象
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 * @param {const std::string&} filename 文件名
 * @param {bool} binary 是否以二进制格式反序列化
 */
bool Variant::DeserializeFromFile(const std::string &filename, VariantSerializeType type)
{
    try
    {
        if (!std::filesystem::exists(filename))
        {
            LOG_ERROR("反序列化失败，文件不存在: %s", filename.c_str());
            return false;
        }

        std::ifstream file(filename, type == VariantSerializeType::Binary ? std::ios::binary : std::ios::in);
        if (!file.is_open())
        {
            LOG_ERROR("反序列化失败，打开文件失败: %s", filename.c_str());
            return false;
        }

        *this = Variant();
        std::vector<uint8_t> data((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
        if (type == VariantSerializeType::Binary)
        {
            FromBinaryString(data);
        }
        else
        {
            FromJsonString(std::string(data.begin(), data.end()));
        }
        file.close();
        return true;
    }
    catch (const std::filesystem::filesystem_error& e)
    {
        LOG_ERROR("文件系统错误: %s（文件: %s）", e.what(), filename.c_str());
        return false;
    }
    catch (const std::exception& e)
    {
        LOG_ERROR("反序列化失败，异常: %s（文件: %s）", e.what(), filename.c_str());
        return false;
    }
}

size_t Variant::CalculateBinarySize() const
{
    size_t size = 0;
    size += 1;
    switch (m_private->m_type)
    {
    case VariantType::Bool:
        size += sizeof(bool);
        break;
    case VariantType::Int:
        size += sizeof(int32_t);
        break;
    case VariantType::UInt:
        size += sizeof(uint32_t);
        break;
    case VariantType::Long:
        size += sizeof(int64_t);
        break;
    case VariantType::ULong:
        size += sizeof(uint64_t);
        break;
    case VariantType::Float:
        size += sizeof(float);
        break;
    case VariantType::Double:
        size += sizeof(double);
        break;
    case VariantType::String:
    {
        const std::string &value = std::any_cast<std::string &>(m_private->m_data);
        size += sizeof(variant_t);
        size += value.size();
        break;
    }

    case VariantType::List:
    {
        const auto &list = std::any_cast<VariantList &>(m_private->m_data);
        size += sizeof(variant_t);
        for (const auto &item : list)
        {
            size += item.CalculateBinarySize();
        }
        break;
    }
    case VariantType::Vector:
    {
        const auto &vector = std::any_cast<VariantVector &>(m_private->m_data);
        size += sizeof(variant_t);
        for (const auto &item : vector)
        {
            size += item.CalculateBinarySize();
        }
        break;
    }
    case VariantType::Set:
    {
        const auto &set = std::any_cast<VariantSet &>(m_private->m_data);
        size += sizeof(variant_t);
        for (const auto &item : set)
        {
            size += item.CalculateBinarySize();
        }
        break;
    }
    case VariantType::Map:
    case VariantType::Hash:
    {
        const auto &map = std::any_cast<std::unordered_map<std::string, Variant> &>(m_private->m_data);
        size += sizeof(variant_t);
        for (const auto &pair : map)
        {
            size += sizeof(uint8_t);
            size += pair.first.size();
            size += pair.second.CalculateBinarySize();
        }
        break;
    }
    case VariantType::Binary:
    {
        const std::vector<uint8_t> &value = std::any_cast<std::vector<uint8_t> &>(m_private->m_data);
        size += sizeof(uint64_t);
        size += value.size();
        break;
    }
    case VariantType::User:
    {
        auto it = m_typeRegistry.find(m_private->m_typeName);
        if (it != m_typeRegistry.end())
        {
            size += sizeof(uint8_t);
            size += m_private->m_typeName.size();
            size += it->second.sesize;
        }
        else
        {
            size += 1;
        }
        break;
    }

    default:
        size += 1;
        break;
    }
    return size;
}

inline void Variant::Indent(std::ostream& os, int depth) const
 {
    for (int i = 0; i < depth; ++i)
    {
        os << "  ";
    }
}

inline void Variant::SerializeJson(std::ostream &os, bool format, int depth) const
{
    switch (m_private->m_type)
    {
        case VariantType::Bool: 
            os << (std::any_cast<bool>(m_private->m_data) ? "true" : "false");
            break;
        case VariantType::Int:
            os << std::any_cast<int>(m_private->m_data);
            break;
        case VariantType::UInt:
            os << std::any_cast<unsigned int>(m_private->m_data);
            break;
        case VariantType::Long:
            os << std::any_cast<long long&>(m_private->m_data);
            break;
        case VariantType::ULong:
            os << std::any_cast<unsigned long long&>(m_private->m_data);
            break;
        case VariantType::Float:
            os << std::any_cast<float>(m_private->m_data);
            break;
        case VariantType::Double:
            os << std::any_cast<double&>(m_private->m_data);
            break;
        case VariantType::String: 
        {
            const std::string& str = std::any_cast<std::string&>(m_private->m_data);
            os << "\"";
            static const std::unordered_map<char, const char*> escapeMap = {
                {'"',  "\\\""},
                {'\\', "\\\\"},
                {'\n', "\\n"},
                {'\r', "\\r"},
                {'\t', "\\t"}
            };
            for (char c : str)
            {
                auto it = escapeMap.find(c);
                if (it != escapeMap.end())
                {
                    os << it->second;
                }
                else
                {
                    os << c;
                }
            }
            os << "\"";
            break;
        }

        case VariantType::List: 
        {
            const auto& list = std::any_cast<VariantList&>(m_private->m_data);
            SerializerJsonSequence(list, os, format, depth);
            break;
        }
        case VariantType::Vector: 
        {
            const auto& vector = std::any_cast<VariantVector&>(m_private->m_data);
            SerializerJsonSequence(vector, os, format, depth);
            break;
        }
        case VariantType::Set: 
        {
            const auto& set = std::any_cast<VariantSet&>(m_private->m_data);
            SerializerJsonSequence(set, os, format, depth);
            break;
        }

        case VariantType::Map: 
        {
            const auto& map = std::any_cast<VariantMap&>(m_private->m_data);
            SerializeJsonMap(map, os, format, depth);
            break;
        }

        // 哈希表类型：同映射处理
        case VariantType::Hash: 
        {
            const auto& hash = std::any_cast<VariantHash&>(m_private->m_data);
            SerializeJsonMap(hash, os, format, depth);
            break;
        }

        // 用户自定义类型
        case VariantType::User:
        {
            auto it = m_jsonTypeRegistry.find(m_private->m_typeName);
            if (it != m_jsonTypeRegistry.end()) 
            {
                Variant variant;
                it->second.first(m_private->m_data, variant);
                variant[VariantJsonType] = m_private->m_typeName;
                variant.SerializeJson(os, format, depth);  // 传递格式参数
            } 
            else 
            {
                LOG_WARN("未注册的JSON序列化类型: %s", m_private->m_typeName.c_str());
                os << "null";
            }
            break;
        }
        default:
            os << "null";
            break;
    }
}

inline void Variant::DeserializeJson(const char*& ptr, const char* end) 
{
    ptr = SkipWhitespace(ptr, end);
    if (ptr >= end) 
    {
        m_private->m_type = VariantType::None;
        return;
    }

    char currentChar = *ptr;
    if (currentChar == '{') 
    {
        ++ptr;
        ptr = SkipWhitespace(ptr, end);
        
        std::unordered_map<std::string, Variant> result;
        result.reserve(16);
        while (ptr < end && *ptr != '}') 
        {
            std::string key;
            ptr = ParseJsonString(ptr, end, key);
            ptr = SkipWhitespace(ptr, end);
            
            if (ptr >= end || *ptr != ':') 
            {
                LOG_WARN("Expected ':' in JSON object");
                break;
            }
            ++ptr;
            ptr = SkipWhitespace(ptr, end);
            result[key].DeserializeJson(ptr, end);
            ptr = SkipWhitespace(ptr, end);
            if (ptr < end && *ptr == ',') 
            {
                ++ptr;
                ptr = SkipWhitespace(ptr, end);
            }
        }
        
        if (ptr < end && *ptr == '}') 
        {
            ++ptr;
        } 
        else 
        {
            LOG_WARN("Expected '}' in JSON object");
        }
        
        auto it = result.find(VariantJsonType);
        if (it != result.end()) 
        {
            auto typeIt = m_jsonTypeRegistry.find(it->second);
            if (typeIt != m_jsonTypeRegistry.end()) 
            {
                m_private->m_data = typeIt->second.second(result);
                m_private->m_type = VariantType::User;
                m_private->m_typeName = it->second.ToString();
                return;
            } 
            else 
            {
                LOG_WARN("Unregistered JSON type: %s", it->second.ToString().c_str());
            }
        }
        m_private->m_data = std::move(result);
        m_private->m_type = VariantType::Hash;
    }
    else if (currentChar == '[') 
    {
        ++ptr;  // 跳过'['
        ptr = SkipWhitespace(ptr, end);
        std::vector<Variant> result;
        result.reserve(16);
        while (ptr < end && *ptr != ']') 
        {
            Variant value;
            value.DeserializeJson(ptr, end);
            result.emplace_back(std::move(value));
            
            ptr = SkipWhitespace(ptr, end);
            if (ptr < end && *ptr == ',') 
            {
                ++ptr;
                ptr = SkipWhitespace(ptr, end);
            }
        }
        
        if (ptr < end && *ptr == ']') 
        {
            ++ptr;
        } 
        else 
        {
            LOG_WARN("Expected ']' in JSON array");
        }
        m_private->m_data = std::move(result);
        m_private->m_type = VariantType::Vector;
//        *this = std::move(result);
    }
    else if (currentChar == '"') 
    {
        std::string str;
        ptr = ParseJsonString(ptr, end, str);
//        *this = std::move(str);
        m_private->m_data = std::move(str);
        m_private->m_type = VariantType::String;
    }
    else if (currentChar == 't' || currentChar == 'f') 
    {
        m_private->m_type = VariantType::Bool;
        if (currentChar == 't') 
        {
            if (ptr + 3 < end && ptr[1] == 'r' && ptr[2] == 'u' && ptr[3] == 'e') 
            {
                m_private->m_data = true;
                ptr += 4;
            } 
            else 
            {
                m_private->m_data = false;
                ++ptr;
            }
        } 
        else 
        {
            if (ptr + 4 < end && ptr[1] == 'a' && ptr[2] == 'l' && ptr[3] == 's' && ptr[4] == 'e') 
            {
                m_private->m_data = false;
                ptr += 5;
            } 
            else 
            {
                m_private->m_data = false;
                ++ptr;
            }
        }
    }
    else if (currentChar == 'n') 
    {
        if (ptr + 3 < end && ptr[1] == 'u' && ptr[2] == 'l' && ptr[3] == 'l') 
        {
            m_private->m_type = VariantType::None;
            ptr += 4;
        } 
        else 
        {
            m_private->m_type = VariantType::None;
            ++ptr;
        }
    }
    else if (currentChar == '-' || (currentChar >= '0' && currentChar <= '9')) 
    {
        ptr = ParseJsonNumber(ptr, end, *this);
    }
    else 
    {
        m_private->m_type = VariantType::None;
        ++ptr;
    }
}

inline const char* Variant::SkipWhitespace(const char* ptr, const char* end) 
{
    while (ptr < end) 
    {
        switch (*ptr) 
        {
            case ' ': 
            case '\t': 
            case '\n': 
            case '\r':
                ++ptr;
                break;
            default:
                return ptr;
        }
    }
    return ptr;
}

inline const char* Variant::ParseJsonString(const char* ptr, const char* end, std::string& out) 
{
    if (ptr >= end || *ptr != '"') 
    {
        out.clear();
        return ptr;
    }
    ++ptr;
    
    const char* start = ptr;
    size_t length = 0;
    bool hasEscape = false;
    
    // 第一遍：计算长度并检查转义符
    while (ptr < end && *ptr != '"') 
    {
        if (*ptr == '\\') 
        {
            hasEscape = true;
            ++ptr;
            if (ptr < end) 
            {
                ++ptr;
            }
            ++length;
        } 
        else 
        {
            ++ptr;
            ++length;
        }
    }
    
    if (ptr >= end) 
    {
        out.clear();
        return ptr;
    }
    
    // 预分配内存
    out.reserve(length);
    ptr = start;
    
    while (ptr < end && *ptr != '"') 
    {
        if (*ptr == '\\') 
        {
            ++ptr;
            if (ptr >= end) 
            {
                break;
            }
            switch (*ptr) 
            {
                case '"':  out += '"';  break;
                case '\\': out += '\\'; break;
                case '/':  out += '/';  break;
                case 'b':  out += '\b'; break;
                case 'f':  out += '\f'; break;
                case 'n':  out += '\n'; break;
                case 'r':  out += '\r'; break;
                case 't':  out += '\t'; break;
                default:   out += *ptr;
            }
            ++ptr;
        } 
        else 
        {
            out += *ptr;
            ++ptr;
        }
    }
    
    ++ptr;
    return ptr;
}

// 优化：手动解析数值（避免std::stoi/stod开销）
inline const char* Variant::ParseJsonNumber(const char* ptr, const char* end, Variant& out) 
{
    const char* start = ptr;
    bool isFloat = false;
    if (*ptr == '-') 
    {
        ++ptr;
    }
    
    while (ptr < end && *ptr >= '0' && *ptr <= '9') 
    {
        ++ptr;
    }
    
    if (ptr < end && *ptr == '.') 
    {
        isFloat = true;
        ++ptr;
        while (ptr < end && *ptr >= '0' && *ptr <= '9') 
        {
            ++ptr;
        }
    }
    
    if (ptr < end && (*ptr == 'e' || *ptr == 'E')) 
    {
        isFloat = true;
        ++ptr;
        if (ptr < end && (*ptr == '+' || *ptr == '-')) 
        {
            ++ptr;
        }
        while (ptr < end && *ptr >= '0' && *ptr <= '9') 
        {
            ++ptr;
        }
    }
    std::string_view numStr(start, ptr - start);
    if (isFloat) 
    {
        out = std::stod(std::string(numStr));  // 浮点数
    } 
    else 
    {
        out = std::stoll(std::string(numStr));
    }
    
    return ptr;
}

/**
 * @description: 将Variant转换为JSON字符串
 * @return {std::string} 返回Variant的JSON字符串表示
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 */
std::string Variant::ToJsonString(bool format)
{
    std::ostringstream oss;
    SerializeJson(oss, format, 0);
    return oss.str();
}

/**
 * @description: 从JSON字符串解析Variant
 * @return {Variant} 返回解析后的Variant对象
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 * @param {const std::string&} jsonStr JSON字符串
 */
void Variant::FromJsonString(const std::string &jsonStr)
{
    // std::istringstream iss(jsonStr);
    // DeserializeJson(iss);
    if(jsonStr == "")
    {
        return;
    }
    const char* ptr = jsonStr.data();
    const char* end = ptr + jsonStr.size();
    DeserializeJson(ptr, end);
}

std::vector<uint8_t> Variant::ToBinaryString()
{
//    std::ostringstream oss(std::ios::binary);
//    SerializeBinary(oss);
//    const std::string& str = oss.str();
//    return std::vector<uint8_t>(str.begin(), str.end());

    //改用先统计再预分配，50万数据提升3-5倍
    size_t totalSize = CalculateBinarySize();
    std::vector<uint8_t> result(totalSize);
    uint8_t* buffer = result.data();
    size_t offset = 0;
    SerializeToBuffer(buffer, offset);
    return result;
}

void Variant::SerializeToBuffer(uint8_t* buffer, size_t& offset) const
{
    buffer[offset++] = static_cast<uint8_t>(m_private->m_type);
    switch (m_private->m_type)
    {
    case VariantType::Bool:
        BinarySerializer<VariantType::Bool>::serialize(*m_private, buffer, offset);
        break;
    case VariantType::Int:
        BinarySerializer<VariantType::Int>::serialize(*m_private, buffer, offset);
        break;
    case VariantType::UInt:
        BinarySerializer<VariantType::UInt>::serialize(*m_private, buffer, offset);
        break;
    case VariantType::Long:
        BinarySerializer<VariantType::Long>::serialize(*m_private, buffer, offset);
        break;
    case VariantType::ULong:
        BinarySerializer<VariantType::ULong>::serialize(*m_private, buffer, offset);
        break;
    case VariantType::Float:
        BinarySerializer<VariantType::Float>::serialize(*m_private, buffer, offset);
        break;
    case VariantType::Double:
        BinarySerializer<VariantType::Double>::serialize(*m_private, buffer, offset);
        break;
    case VariantType::String:
    {
        const std::string &value = std::any_cast<std::string &>(m_private->m_data);
        variant_t length = static_cast<variant_t>(value.size());
        variant_t size = ToBigEndian(length);

        std::memcpy(buffer + offset, &size, sizeof(size));
        offset += sizeof(size);
        std::memcpy(buffer + offset, value.data(), length);
        offset += length;
        break;
    }
    case VariantType::List:
    {
        const auto &list = std::any_cast<VariantList &>(m_private->m_data);
        variant_t size = static_cast<variant_t>(list.size());
        size = ToBigEndian(size);
        std::memcpy(buffer + offset, &size, sizeof(size));
        offset += sizeof(size);

        for (const auto &item : list)
        {
            item.SerializeToBuffer(buffer, offset);
        }
        break;
    }
    case VariantType::Vector:
    {
        const auto &vector = std::any_cast<VariantVector &>(m_private->m_data);
        variant_t size = static_cast<variant_t>(vector.size());
        size = ToBigEndian(size);
        std::memcpy(buffer + offset, &size, sizeof(size));
        offset += sizeof(size);

        for (const auto &item : vector)
        {
            item.SerializeToBuffer(buffer, offset);
        }
        break;
    }
    case VariantType::Set:
    {
        const auto &set = std::any_cast<VariantSet &>(m_private->m_data);
        variant_t size = static_cast<variant_t>(set.size());
        size = ToBigEndian(size);
        std::memcpy(buffer + offset, &size, sizeof(size));
        offset += sizeof(size);
        for (const auto &item : set)
        {
            item.SerializeToBuffer(buffer, offset);
        }
        break;
    }
    case VariantType::Map:
    {
        const auto &map = std::any_cast<VariantMap &>(m_private->m_data);
        variant_t size = static_cast<variant_t>(map.size());
        size = ToBigEndian(size);
        std::memcpy(buffer + offset, &size, sizeof(size));
        offset += sizeof(size);

        for (const auto &pair : map)
        {
            uint8_t keyLength = static_cast<uint8_t>(pair.first.size());
            std::memcpy(buffer + offset, &keyLength, sizeof(keyLength));
            offset += sizeof(keyLength);

            std::memcpy(buffer + offset, pair.first.data(), keyLength);
            offset += keyLength;
            pair.second.SerializeToBuffer(buffer, offset);
        }
        break;
    }
    case VariantType::Hash:
    {
        const auto &hash = std::any_cast<VariantHash &>(m_private->m_data);
        variant_t size = static_cast<variant_t>(hash.size());
        size = ToBigEndian(size);
        std::memcpy(buffer + offset, &size, sizeof(size));
        offset += sizeof(size);

        for (const auto &pair : hash)
        {
            uint8_t keyLength = static_cast<uint8_t>(pair.first.size());
            std::memcpy(buffer + offset, &keyLength, sizeof(keyLength));
            offset += sizeof(keyLength);

            std::memcpy(buffer + offset, pair.first.data(), keyLength);
            offset += keyLength;
            pair.second.SerializeToBuffer(buffer, offset);
        }
        break;
    }
    case VariantType::Binary:  // 添加二进制类型的序列化
    {
        const std::vector<uint8_t> &value = std::any_cast<std::vector<uint8_t> &>(m_private->m_data);
        uint64_t length = static_cast<uint64_t>(value.size());
        uint64_t size = ToBigEndian(length);
        std::memcpy(buffer + offset, &size, sizeof(size));
        offset += sizeof(size);

        std::memcpy(buffer + offset, value.data(), length);
        offset += length;
        break;
    }
    case VariantType::User:
    {
        auto it = m_typeRegistry.find(m_private->m_typeName);
        if (it != m_typeRegistry.end())
        {
            uint8_t typeNameLength = static_cast<uint8_t>(m_private->m_typeName.size());
            std::memcpy(buffer + offset, &typeNameLength, sizeof(typeNameLength));
            offset += sizeof(typeNameLength);

            std::memcpy(buffer + offset, m_private->m_typeName.data(), typeNameLength);
            offset += typeNameLength;
            it->second.serialize(m_private->m_data, buffer, offset);
        }
        else
        {
            LOG_ERROR("未注册二进制序列化类型: %s", m_private->m_typeName.c_str());
        }
        break;
    }
    default:
        buffer[offset++] = 'n';  // 占位
        break;
    }
}

void Variant::FromBinaryString(const std::vector<uint8_t>& binaryStr)
{
    const uint8_t* buffer = binaryStr.data();
    size_t offset = 0;
    DeserializeFromBuffer(buffer, offset);
}

inline void Variant::DeserializeFromBuffer(const uint8_t* buffer, size_t& offset)
{
    uint8_t type = buffer[offset++];
    m_private->m_type = static_cast<VariantType>(type);
    switch (m_private->m_type)
    {
    case VariantType::Bool:
        BinaryDeSerializer<VariantType::Bool>::deserialize(*m_private, buffer, offset);
        break;
    case VariantType::Int:
        BinaryDeSerializer<VariantType::Int>::deserialize(*m_private, buffer, offset);
        break;
    case VariantType::UInt:
        BinaryDeSerializer<VariantType::UInt>::deserialize(*m_private, buffer, offset);
        break;
    case VariantType::Long:
        BinaryDeSerializer<VariantType::Long>::deserialize(*m_private, buffer, offset);
        break;
    case VariantType::ULong:
        BinaryDeSerializer<VariantType::ULong>::deserialize(*m_private, buffer, offset);
        break;
    case VariantType::Float:
        BinaryDeSerializer<VariantType::Float>::deserialize(*m_private, buffer, offset);
        break;
    case VariantType::Double:
        BinaryDeSerializer<VariantType::Double>::deserialize(*m_private, buffer, offset);
        break;
    case VariantType::String:
    {
        variant_t size;
        std::memcpy(&size, buffer + offset, sizeof(size));
        offset += sizeof(size);
        size = FromBigEndian(size);
        std::string value;
        if (size > 0)
        {
            value.assign(reinterpret_cast<const char*>(buffer + offset), size);
            offset += size;
        }
        m_private->m_data = std::move(value);
        break;
    }
    case VariantType::List:
    {
        variant_t size;
        std::memcpy(&size, buffer + offset, sizeof(size));
        offset += sizeof(size);
        size = FromBigEndian(size);
        std::list<Variant> list;
        for (variant_t i = 0; i < size; ++i)
        {
            Variant item;
            item.DeserializeFromBuffer(buffer, offset);
            list.emplace_back(std::move(item));
        }
        m_private->m_data = std::move(list);
        break;
    }
    case VariantType::Vector:
    {
        variant_t size;
        std::memcpy(&size, buffer + offset, sizeof(size));
        offset += sizeof(size);
        size = FromBigEndian(size);
        std::vector<Variant> vec;
        vec.reserve(size);
        for (variant_t i = 0; i < size; ++i)
        {
            Variant item;
            item.DeserializeFromBuffer(buffer, offset);
            vec.emplace_back(std::move(item));
        }
        m_private->m_data = std::move(vec);
        break;
    }
    case VariantType::Set:
    {
        variant_t size;
        std::memcpy(&size, buffer + offset, sizeof(size));
        offset += sizeof(size);
        size = FromBigEndian(size);
        std::set<Variant> set;
        for (variant_t i = 0; i < size; ++i)
        {
            Variant item;
            item.DeserializeFromBuffer(buffer, offset);
            set.emplace(std::move(item));
        }
        m_private->m_data = std::move(set);
        break;
    }
    case VariantType::Map:
    {
        variant_t size;
        std::memcpy(&size, buffer + offset, sizeof(size));
        offset += sizeof(size);
        size = FromBigEndian(size);
        std::map<std::string, Variant> map;
        for (variant_t i = 0; i < size; ++i)
        {
            uint8_t keyLength = buffer[offset++];
            std::string key;
            if (keyLength > 0)
            {
                key.assign(reinterpret_cast<const char*>(buffer + offset), keyLength);
                offset += keyLength;
            }
            Variant value;
            value.DeserializeFromBuffer(buffer, offset);
            map.emplace(std::move(key), std::move(value));
        }
        m_private->m_data = std::move(map);
        break;
    }
    case VariantType::Hash:
    {
        variant_t size;
        std::memcpy(&size, buffer + offset, sizeof(size));
        offset += sizeof(size);
        size = FromBigEndian(size);
        std::unordered_map<std::string, Variant> hash;
        hash.reserve(size);
        for (variant_t i = 0; i < size; ++i)
        {
            uint8_t keyLength = buffer[offset++];
            std::string key;
            if (keyLength > 0)
            {
                key.assign(reinterpret_cast<const char*>(buffer + offset), keyLength);
                offset += keyLength;
            }
            Variant value;
            value.DeserializeFromBuffer(buffer, offset);
            hash.emplace(std::move(key), std::move(value));
        }
        m_private->m_data = std::move(hash);
        break;
    }
    case VariantType::Binary:
    {
        uint64_t size;
        std::memcpy(&size, buffer + offset, sizeof(size));
        offset += sizeof(size);
        size = FromBigEndian(size);
        std::vector<uint8_t> value;
        if (size > 0)
        {
            value.assign(buffer + offset, buffer + offset + size);
            offset += size;
        }
        m_private->m_data = std::move(value);
        break;
    }
    case VariantType::User:
    {
        uint8_t typeNameLength = buffer[offset++];
        std::string typeName;
        if (typeNameLength > 0)
        {
            typeName.assign(reinterpret_cast<const char*>(buffer + offset), typeNameLength);
            offset += typeNameLength;
        }

        auto it = m_typeRegistry.find(typeName);
        if (it != m_typeRegistry.end())
        {
            m_private->m_typeName = std::move(typeName);
            m_private->m_data = it->second.deserialize(buffer, offset);
            m_private->m_type = VariantType::User;
        }
        else
        {
            LOG_ERROR("未注册二进制序列化类型: %s", typeName.c_str());
            *this = Variant();
        }
        break;
    }
    default:
        ++offset;
        break;
    }
}

/**
 * @description: 重载输出运算符，用于将Variant对象输出到输出流
 * @return {std::ostream&} 返回输出流
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 * @param {std::ostream&} os 输出流
 * @param {const Variant&} variant 要输出的Variant对象
 */
std::ostream &operator<<(std::ostream &os, const Variant &variant)
{
    variant.SerializeJson(os);
    return os;
}

/**
 * @description: 重载输入运算符，用于从输入流中读取Variant对象
 * @return {std::istream&} 返回输入流
 * @Author: dengzhijun
 * @Date: 2025-01-17 10:09:56
 * @LastEditTime: Do not edit
 * @LastEditors: dengzhijun
 * @param {std::istream&} is 输入流
 * @param {Variant&} variant 要读取的Variant对象
 */
// std::istream &operator>>(std::istream &is, Variant &variant)
// {
//     variant.DeserializeJson(is);
//     return is;
// }

bool Variant::operator==(const Variant &other) const
{
    if (this->m_private->m_type != other.m_private->m_type)
    {
        return false;
    }

    if (this->m_private->m_typeName != other.m_private->m_typeName)
    {
        return false;
    }

    switch (this->m_private->m_type)
    {
    case VariantType::Bool:
        return this->Value<bool>() == other.Value<bool>();
    case VariantType::Int:
        return this->Value<int>() == other.Value<int>();
    case VariantType::UInt:
        return this->RefValue<unsigned int>() == other.RefValue<unsigned int>();
    case VariantType::Long:
        return this->RefValue<long long>() == other.RefValue<long long>();
    case VariantType::ULong:
        return this->RefValue<unsigned long long>() == other.RefValue<unsigned long long>();
    case VariantType::Float:
        return this->RefValue<float>() == other.RefValue<float>();
    case VariantType::Double:
        return this->RefValue<double>() == other.RefValue<double>();
    case VariantType::String:
        return this->RefValue<std::string>() == other.RefValue<std::string>();
    case VariantType::List:
    {
        const auto &thisList = this->RefValue<std::list<Variant>>();
        const auto &otherList = other.RefValue<std::list<Variant>>();
        if (thisList.size() != otherList.size())
        {
            return false;
        }
        auto it1 = thisList.begin();
        auto it2 = otherList.begin();
        while (it1 != thisList.end() && it2 != otherList.end())
        {
            if (*it1 != *it2)
            {
                return false;
            }
            ++it1;
            ++it2;
        }
        return true;
    }
    case VariantType::Vector:
    {
        const auto &thisVector = this->RefValue<std::vector<Variant>>();
        const auto &otherVector = other.RefValue<std::vector<Variant>>();
        if (thisVector.size() != otherVector.size())
        {
            return false;
        }
        for (size_t i = 0; i < thisVector.size(); ++i)
        {
            if (thisVector[i] != otherVector[i])
            {
                return false;
            }
        }
        return true;
    }
    case VariantType::Set:
    {
        const auto &thisSet = this->RefValue<std::set<Variant>>();
        const auto &otherSet = other.RefValue<std::set<Variant>>();
        if (thisSet.size() != otherSet.size())
        {
            return false;
        }
        auto it1 = thisSet.begin();
        auto it2 = otherSet.begin();
        while (it1 != thisSet.end() && it2 != otherSet.end())
        {
            if (*it1 != *it2)
            {
                return false;
            }
            ++it1;
            ++it2;
        }
        return true;
    }
    case VariantType::Map:
    {
        const auto &thisMap = this->RefValue<std::map<std::string, Variant>>();
        const auto &otherMap = other.RefValue<std::map<std::string, Variant>>();
        if (thisMap.size() != otherMap.size())
        {
            return false;
        }
        for (const auto &[key, value] : thisMap)
        {
            auto it = otherMap.find(key);
            if (it == otherMap.end() || value != it->second)
            {
                return false;
            }
        }
        return true;
    }
    case VariantType::Hash:
    {
        const auto &thisHash = this->RefValue<std::unordered_map<std::string, Variant>>();
        const auto &otherHash = other.RefValue<std::unordered_map<std::string, Variant>>();
        if (thisHash.size() != otherHash.size())
        {
            return false;
        }
        for (const auto &[key, value] : thisHash)
        {
            auto it = otherHash.find(key);
            if (it == otherHash.end() || value != it->second)
            {
                return false;
            }
        }
        return true;
    }
    case VariantType::User:
    {
        return this->m_private->m_typeName == other.m_private->m_typeName;
    }
    case VariantType::None:
        return true;
    default:
        return false;
    }
    return true;
}

bool Variant::operator!=(const Variant &other) const
{
    return !(*this == other);
}

bool Variant::operator<(const Variant &other) const
{
    return this->m_private->m_type < other.m_private->m_type;
}

bool Variant::operator>(const Variant &other) const
{
    return this->m_private->m_type > other.m_private->m_type;
}

bool Variant::operator<=(const Variant &other) const
{
    return !(*this > other);
}

bool Variant::operator>=(const Variant &other) const
{
    return !(*this < other);
}

bool Variant::Contains(const std::string &key) const
{
    if(m_private->m_type == VariantType::Hash)
    {
        VariantHash &hash = RefValue<VariantHash>();
        if(hash.find(key) != hash.end())
        {
            return true;
        }
    }
    if(m_private->m_type == VariantType::Map)
    {
        VariantMap &map = RefValue<VariantMap>();
        if(map.find(key) != map.end())
        {
            return true;
        }
    }
    return false;
}

const std::string &Variant::GetTypeName() const
{
    return m_private->m_typeName;
}

bool Variant::IsNull() const
{
    return m_private->m_type == VariantType::None;
}

}
